package com.coconet.gas.until;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.coconet.gas.vo.dw.BaseWapper;

public class ConvertVoToMap<M extends BaseWapper> {

	public static HttpServletRequest getRequest() {
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes();
		return requestAttributes == null ? null : requestAttributes.getRequest();
	}

	public static String getIp() {
		HttpServletRequest request = getRequest();
		return request == null ? "127.0.0.1" : request.getRemoteHost();
	}
	public  Map<String, Object> CVTM(M ob) {
		return ob.convertThis2Map();
	}

	public  List<Map<String, Object>> CVTMLi(List<M> ob) {
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for (M op : ob) {			
			result.add(op.convertThis2Map());
		}
		return result;
	}

}
